package com.meaningful.design_pattern.chain_of_responsibility.validation;

public class MaxValidatorHandler implements ValidationHandler {

    private final int max;

    public MaxValidatorHandler(int max) {
        this.max = max;
    }

    @Override
    public void validate(Object value, ValidatorContext context) throws ValidatorException {
        if (value instanceof Integer intValue) {
            if (intValue > max) {
                context.appendError(String.format("%d大于%d", intValue, max));
            }
        }
        context.doNext(value);
    }

}
